public class ThreadDemo3 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {//创建 Runnable 实例 作为Thread类的构造方法的参数。创建时，使用匿名内部类
            @Override
            public void run() {
                while(true){
                    System.out.println("hello thread\n");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });

        thread.start();//方法调用

        while(true){
            System.out.println("hello main\n");
            Thread.sleep(1000);
        }
    }
}
